package cn.itheima.user.controller;

import cn.itheima.dubbo.api.OrderService;
import cn.itheima.dubbo.domain.Order;
import cn.itheima.dubbo.domain.User;
import cn.itheima.user.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
       @Autowired
    private UserService userService;
    @DubboReference
    private OrderService orderService;

@GetMapping("/{id}")
    public User getById(@PathVariable Long id){
    User user = userService.getById(id);
    List<Order> orders = orderService.findByUserId(id);
    user.setOrder(orders);
    return user;
}
}
